package com.sie.tools;

import java.util.TimerTask;

public class Timer {
    private long timeOutMs = 0L;
    private boolean bTimeOut = false;
    Timer tm = null;
    java.util.Timer timer = new java.util.Timer();
    public Timer() {
        this.timeOutMs = 0L;
        this.bTimeOut = false;
    }

    public Timer(long timeOutMs) {
        this.timeOutMs = timeOutMs;
        this.bTimeOut = false;
    }

    public void setTimeOutMs(long ms) {
        this.timeOutMs = ms;
    }

    public long getTimeOutMs() {
        return this.timeOutMs;
    }

    public void setTimOut() {
        this.bTimeOut = true;
        timer.cancel();
    }

    public void start() {

        tm = this;
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                tm.setTimOut();
            }
        };
        timer.schedule(task, timeOutMs);

    }

    public boolean timeOut() {
        return this.bTimeOut;
    }
}